<template>
    <view style="padding: 10px">分享给：</view>
    <uni-list>
    	<uni-list-item v-for="(item, index) in shareCustomer" :key="index" clickable @click="gotoRelationship(item)">
    		<!-- 自定义 header -->
    		<template v-slot:header>
    			<view style="display: flex; align-items: center">
    				<image style="width: 40px; height: 40px; border-radius: 20px"
    					:src="item.cust?.ciAvat ? item.cust?.ciAvat: tempImageUrl" mode="widthFix">
    				</image>
    				<view style="margin-left: 8px; font-size: 13px">
    					<view>{{ (item.cust?.ciName || '') + (item.cust?.ciAlia ? '(' + item.cust?.ciAlia + ')' : '') }}</view>
    					<view>{{ (item.cust?.ciPhon || '') }}</view>
    				</view>
    			</view>
    		</template>
    		<!-- 自定义 footer-->
    		<template v-slot:footer>
                <view style="display: flex; align-items: center;">
                	<view style="font-size: 14px;">{{UTCTimeToLocal(item.clTime)}}</view>
                	<uni-icons type="forward" size="20" color="#C0C0C0"></uni-icons>
                </view>
    		</template>
    	</uni-list-item>
    </uni-list>
    <u-empty v-if="shareCustomer.length === 0" text="暂无数据"> </u-empty>
</template>

<script>
    import {
        getMyCustomerRelationship
    } from "../../utils/api.js"
    import { mapGetters } from "vuex";
    
    export default {
        data() {
            return {
                shareCustomer: [],
                tempImageUrl: "http://jdc.jd.com/img/100x100/",
            }
        },
        onLoad(params) {
            if (params.ciUuid) {
                this.loadMyCustomerRelationship({ gpUuid: this.activity.gpUuid, scUuid: params.ciUuid})
            }
        },
        computed: {
            ...mapGetters({
                activity: "activityInfo/activity",
            }),
        },
        methods: {
            async loadMyCustomerRelationship({gpUuid, scUuid}) {
                let res = await getMyCustomerRelationship({
                    gpUuid,
                    scUuid
                })
                if (res) {
                    let shareCustomer = []
                    res.map(item => {
                        if (shareCustomer.findIndex(_item => _item.ciUuid === item.ciUuid) === -1) {
                            shareCustomer.push(item)
                        }
                    })
                    this.shareCustomer = shareCustomer
                }
            },
            
            gotoRelationship(item) {
                if (this.shareCustomer.length > 0) {
                    uni.redirectTo({
                        url:`/pages/staff/customer_fission_customer?ciUuid=${item.ciUuid}`
                    })
                }
            }
        }
    }
</script>

<style>
</style>